home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / PluginSRC_EvenMore / WordWorth2Text.e < prev    next >
Encoding:
Text File  |  2002-03-13  |  4.4 KB  |  190 lines

  1. /*
  2.    WordWorth2Text
  3.    EvenMore FileIO plugin
  4.    Author: Chris Perver
  5.    Copyright (c) 2001
  6. */
  7.  
  8.  
  9. OPT REG=5
  10.  
  11. LIBRARY 'wordworth2text.plugin',1,1,'WordWorth2Text 1.02' IS em_main, em_end, em_info, em_pluginid, em_begin, em_format
  12.  
  13. MODULE 'tools/ctype', '*epo'
  14.  
  15. DEF vers, mem2, len2
  16.  
  17.  
  18. PROC em_isdatatype(memadr, lenadr)
  19.    DEF vers = 0
  20.    DEF w:PTR TO LONG
  21.  
  22.  
  23.    -> Check for FORM header
  24.  
  25.    vers := 1
  26.    w := Long(memadr)
  27.    IF w = "FORM"
  28.      w := Long(memadr + 8)
  29.      IF w <> "WOWO" THEN vers := 0
  30.    ELSE
  31.      vers := 0
  32.    ENDIF
  33. ENDPROC vers
  34.  
  35.  
  36. PROC em_parsedata(memadr, lenadr)
  37.   DEF count = 0, count2 = 0
  38.   DEF wrapping = 80, notdonewrapping = TRUE, currchar = 0
  39.   DEF notdone = TRUE
  40.   -> Allocate memory for file
  41. ->  IF (mem2 := New(lenadr + 1)) = NIL THEN RETURN -1
  42. ->  mem2[lenadr + 1] := "\n"                                                      -> Put safety LF at the end of mem
  43.   DEF w:PTR TO LONG
  44.   DEF iswtxt = FALSE
  45.  
  46.   mem2 := memadr
  47.  
  48.    WHILE notdone AND (count < lenadr)
  49.      IF (currchar >= wrapping)
  50.        WHILE notdonewrapping
  51.          SELECT 256 OF memadr[count]
  52.            CASE $00
  53.              DEC count
  54.            DEFAULT
  55.              IF isspace(memadr[count]) = FALSE
  56.                DEC count
  57.                DEC count2
  58.              ELSE
  59.                notdonewrapping := FALSE
  60.              ENDIF
  61.          ENDSELECT
  62.        ENDWHILE
  63.        INC count
  64.  
  65.        currchar := 0
  66.        memadr[count2++] := "\n"
  67.        notdonewrapping := TRUE
  68.      ENDIF
  69.  
  70.      WHILE memadr[count] <> "W" DO INC count
  71.  
  72.      w := Long(memadr + count)
  73.    ->  WriteF('\s\n', w)
  74.      SELECT w
  75.        CASE "WPAR"
  76.          INC count
  77.  
  78.  
  79.        CASE "WTXT"
  80.          count := count + 8
  81.          iswtxt := TRUE
  82.          WHILE iswtxt
  83.  
  84.            SELECT 256 OF memadr[count]
  85.              CASE "W"
  86.                w := Long(memadr + count)
  87.                 -> WW3 docs don#t have LF/CR!
  88.                SELECT w
  89.                  CASE "WTXT"
  90.                    DEC count
  91.                    memadr[count2++] := "\n"
  92.                    iswtxt := FALSE
  93.                    currchar := 0
  94.                  CASE "WPAR"
  95.                    count := count + 8
  96.                    iswtxt := FALSE
  97.                  CASE "WFSC"
  98.                    count := count + 8
  99.                    iswtxt := FALSE
  100.                  CASE "WHED"
  101.                    iswtxt := FALSE
  102.                    notdone := FALSE
  103.                  DEFAULT
  104.                    SELECT 256 OF memadr[count]
  105.                      CASE $00
  106.                        INC count
  107.                      CASE $0f
  108.  
  109.                        IF memadr[count + 1] <> $00
  110.                          w := Long(memadr + count + 1)
  111.                          IF w <> "WTXT"
  112.                            memadr[count2++] := "\n"
  113.                            currchar := 0
  114.                          ENDIF
  115.                        ENDIF
  116.                        INC count
  117.                      DEFAULT
  118.                        memadr[count2++] := memadr[count++]
  119.                        INC currchar
  120.                    ENDSELECT
  121.                  ENDSELECT
  122.                DEFAULT
  123.                  SELECT 256 OF memadr[count]
  124.                    CASE $00
  125.                      INC count
  126.                    CASE $0f
  127.                      IF memadr[count + 1] <> $00
  128.                        w := Long(memadr + count + 1)
  129.                        IF w <> "WTXT"
  130.                          memadr[count2++] := "\n"
  131.                          currchar := 0
  132.                        ENDIF
  133.                      ENDIF
  134.                      INC count
  135.                    DEFAULT
  136.                      memadr[count2++] := memadr[count++]
  137.                      INC currchar
  138.                ENDSELECT
  139.            ENDSELECT
  140.          ENDWHILE
  141.  
  142.  
  143.  
  144.          INC count
  145.        CASE "WHED"
  146.          notdone := FALSE
  147.        DEFAULT
  148.          INC count
  149.      ENDSELECT
  150.  
  151.    ENDWHILE
  152.  
  153.  
  154.   mem2[count2] := "\n"
  155.  
  156.  -> IF memadr
  157.  ->   Dispose(memadr); memadr := NIL
  158.  -> ENDIF
  159. ENDPROC mem2, count2
  160. -><
  161.  
  162. -> *** STANDARD PROCS FOR PLUGINS
  163.  
  164.  
  165. PROC em_main(epo:PTR TO em_pluginobj)
  166.     mem2, len2 := em_parsedata(epo.buffer, epo.length)
  167.     epo.buffer := mem2
  168.     epo.length := len2
  169.     RETURN TRUE
  170. ENDPROC
  171.  
  172. PROC em_begin(epo:PTR TO em_pluginobj)
  173.   vers := em_isdatatype(epo.buffer, epo.length)
  174.   IF vers
  175.     RETURN TRUE
  176.   ELSE
  177.     RETURN FALSE
  178.   ENDIF
  179. ENDPROC
  180.  
  181. PROC em_end()      IS EMPTY
  182.  
  183. PROC em_info()     IS 'WordWorth2Text 1.02'
  184.  
  185. PROC em_pluginid() IS "FILE"
  186.  
  187. PROC em_format()   IS 'WordWorth'
  188.  
  189. PROC main()        IS EMPTY
  190.